import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { get } from '@/utils/request'

export const useStockDetailStore = defineStore('stockDetail', () => {
  const stockDetail = ref({})
  const klineData = ref([])
  const getStockDetailRef = () => stockDetail.value;
  const getKlineDataRef = () => klineData.value;
  function setKlineData(val) {
    klineData.value = val
  }
  function setStockDetail(val) {
    stockDetail.value = val;
  }
  function getKlineData(start_date, end_date, stockData = stockDetail.value) {
    const params = {
      symbol: stockData['代码'],
      start_date,
      end_date,
      period: "daily"
    }
    get(`/stock_zh_a_hist`, params).then(res => {
      setKlineData(res)
    })
  }
  return { setStockDetail, getKlineData, getStockDetailRef, getKlineDataRef }
})
